package com.example.transactiondemo.controller;

import com.example.transactiondemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user1")
public class UserController1 {
    @Autowired UserService userService;
    //声明式事务
    @Transactional//在方法开启之前开启事务，方法正常执行结束后提交事务，如果发生异常直接回滚事务
    @RequestMapping("/del")
    public int del(Integer id) {
        if (id == null || id <= 0) return 0;
        int result = userService.del(id);
        System.out.println("删除开始");
        int i = 10/0;
        return result;
    }
}
